<?php
/**
 * Description:
 * Author: hezhizheng
 * Date: 2018/10/18
 * Time: 14:45
 * Created by Created by Panxsoft.
 */

namespace App\Services\Factories;

use App\Exceptions\ApiErrCode;
use App\Exceptions\ApiException;
use App\Services\Repositories\Admin\CustomerAdminRepository;
use App\Services\Repositories\Admin\PanxAdminRepository;
use App\Services\Repositories\Admin\StoreAdminRepository;
use App\Services\Repositories\Connector\AdminInterface;
use App\Services\Utils\ApiChecker;

class AdminFactory
{
    const LOGIN_TYPE_PANX = 'panx';
    const LOGIN_TYPE_CUSTOMER = 'customer';
    const LOGIN_TYPE_STORE = 'store';

    use ApiChecker;


    /**
     * @param $type
     * @return CustomerAdminRepository|PanxAdminRepository|StoreAdminRepository|AdminInterface
     * @throws ApiException
     * @throws \App\Exceptions\ApiSilentException
     */
    public static function create($type) : AdminInterface
    {
        switch ($type) {
            case self::LOGIN_TYPE_PANX:
                return  new PanxAdminRepository;
                break;
            case self::LOGIN_TYPE_CUSTOMER:
                return  new CustomerAdminRepository;
                break;
            case self::LOGIN_TYPE_STORE:
                return  new StoreAdminRepository;
                break;
            default:
                throw new ApiException(ApiErrCode::CUSTOMIZE_ERROR, 'error login type');
        }
    }
}